import { HttpServer } from 'src/common/core/http';
import { IHttpServer } from '../core/http/interface';


export enum httpServicesEnum {
  mockHttpServer =  "mockHttpServer"
}

export class HttpServerFactory{
  public static current = new HttpServerFactory()

  private map = new Map<httpServicesEnum, IHttpServer>()
  private httpServiceGenerator = [
    { name: httpServicesEnum.mockHttpServer, loader: () => new HttpServer('https://www.easy-mock.com/mock/5b55575020511b117b20c758/example')}
  ]

  public getHttpServer (name:httpServicesEnum):IHttpServer {
    const httpServer = this.map.get(name)
    if (httpServer) {
      return httpServer
    }
    const generator = this.httpServiceGenerator.find(x => x.name === name)
    if (!generator) {
      throw new Error(`can't find httpServcie by ${name}`)
    }
    this.map.set(name, generator.loader())
    return this.getHttpServer(name)
  }
}